package com.kfm.am;

public class GirlFriend {

    private int age;
    private String name;
    private double weight;

    public int getAge() {
        return age;
    }

    public void setAge(int age) throws AgeIllegalException {
        if (age < 18 || age > 30) {
            throw new AgeIllegalException("女朋友年龄不合适！");
        }
        this.age = age;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public double getWeight() {
        return weight;
    }

    public void setWeight(double weight) {
        if (weight > 140) {
            throw new WeightIllegalException("体重不合适！");
        }
        this.weight = weight;
    }

    @Override
    public String toString() {
        return "GirlFriend{" +
                "age=" + age +
                ", name='" + name + '\'' +
                ", weight=" + weight +
                '}';
    }
}

class Test02 {

    public static void main(String[] args) {

        GirlFriend gf = new GirlFriend();
        gf.setName("迪丽热巴");
        try {
            gf.setAge(16);

        } catch (AgeIllegalException e) {
            System.out.println(e.getMessage());
        }

        try {
            gf.setWeight(150.0);
        } catch (WeightIllegalException e) {
            System.out.println(e.getMessage());
        }

        System.out.println(gf);
    }
}
